from pydantic import BaseModel, fields, model_validator
from api.application import settings
from api.application.utils import tools


class UserInfoRegRequest(BaseModel):
    mobile: str = fields.Field(pattern='^1[3-9]\d{9}', description="手机号")
    password: str = fields.Field(min_length=6, max_length=20, description="密码")
    sms_code: str = fields.Field(max_length=4, description="短信验证码")
    nickName: str = fields.Field(description="微信昵称")
    avatarUrl: str = fields.Field(description="微信头像")
    gender: int = fields.Field(description="性别")
    country: str = fields.Field(description="国家")
    province: str = fields.Field(description="省份")
    city: str = fields.Field(description="城市")
    code: str = fields.Field(description="微信授权码【10分钟有效】")

    @model_validator(mode='after')
    def mode_valicator(self):
        hashing = tools.Hashing()
        self.password = hashing.hash(self.password)
        return self


class BaseResponse(BaseModel):
    code: int = fields.Field(description='状态码')
    err_msg: str = fields.Field(description='响应结果')
    status: str = fields.Field(description='状态文本提示')


class UserInfoRegResponse(BaseResponse):
    id: int = fields.Field(description='用户id')
    avatar: str = fields.Field(description='头像')
    nickname: str = fields.Field(description='昵称')
    token: str = fields.Field(description='token令牌')


# from pydantic import BaseModel, fields, model_validator
# from api.application import settings
# from api.application.utils import tools
#
#
# class UserInfoRequest(BaseModel):
#     """用户登录/注册接口的请求数据结构"""
#     mobile: str = fields.Field(pattern='^1[3-9]\d{9}', description='手机号')
#     password: str = fields.Field(min_length=6, max_length=16, description='密码')
#     sms_code: str = fields.Field(max_length=4, description='短信验证码')
#     avatarUrl: str = fields.Field(description='微信头像')
#     nickName: str = fields.Field(description='微信昵称')
#     gender: bool = fields.Field(description='性别')
#     country: str = fields.Field(description='国家')
#     province: str = fields.Field(description='省份')
#     city: str = fields.Field(description='城市')
#     code: str = fields.Field(description='授权码[10分钟内有效]')
#
#     @model_validator(mode='after')
#     def model_validator(self):
#         # 对密码进行哈希加密
#         hashing = tools.Hashing()
#         self.password = hashing.hash(self.password)
#
#         return self
#
#
# class BaseResponse(BaseModel):
#     code: int = fields.Field(description='状态码')
#     err_msg: str = fields.Field(description='响应结果提示')
#     status: str = fields.Field(description='状态文本提示')
#
#
# class UserInfoResponse(BaseResponse):
#     """用户登录/注册接口的响应数据结构"""
#     id: int = fields.Field(description='用户ID')
#     avatar: str = fields.Field(description='用户头像')
#     nickname: str = fields.Field(description='用户昵称')
#     token: str = fields.Field(description='Token令牌')